package com.hmall.search.web;

import com.hmall.common.client.ItemClient;
import com.hmall.common.dto.FiltersDto;
import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.Filters;
import com.hmall.common.pojo.Item;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
 *   Description SeaechController
 *   @author zhangyan
 *   @time   2024/11/13
 */
@RestController
@RequestMapping("search")
public class SeaechController {
    @Autowired
    private ItemClient itemClient;

    @PostMapping("filters")
    public Filters filter(@RequestBody FiltersDto filtersDto) {
//        Item byId = itemClient.getById(317580L);
        Filters filters = itemClient.selectFilters(filtersDto);
        return filters;
        //  return null;
    }

    /**
     * 条件查询
     *
     * @param filtersDto
     * @return
     */
    @Autowired
    private SearchService searchService;

    @PostMapping("/list")
    public PageDTO<Item> list(@RequestBody FiltersDto filtersDto) {
        //1.feign调用itemservice
        //return itemClient.searchByCondition(filtersDto);

        //2.使用elasticsearch
        return searchService.searchByCondition(filtersDto);
    }
}
